/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pass.jtorrenteditor.helper;

import java.io.File;

/**
 *
 * @author alabuschagne
 */
public class Utils
{
    public final static String torrent = "torrent";

    /*
     * Get the extension of a file.
     */
    public static String getExtension(File f)
    {
        String ext = null;
        String s = f.getName();
        int i = s.lastIndexOf('.');

        if(i > 0 && i < s.length() - 1)
        {
            ext = s.substring(i + 1).toLowerCase();
        }
        return ext;
    }

    public static char[] short2Char(short[] bytes)
    {
        char[] cbytes = new char[bytes.length];
        for(int i = 0; i < bytes.length; i++)
        {
            cbytes[i] = (char) bytes[i];
        }
        return cbytes;
    }

    public static char[] byte2Char(byte[] bytes)
    {
        char[] cbytes = new char[bytes.length];
        for(int i = 0; i < bytes.length; i++)
        {
            cbytes[i] = (char) bytes[i];
        }
        return cbytes;
    }

    public static short[] byte2Short(byte[] bytes)
    {
        short[] sbytes = new short[bytes.length];
        for(int i = 0; i < bytes.length; i++)
        {
            sbytes[i] = (short) bytes[i];
        }
        return sbytes;
    }

    public static String addLeadingZeros(String str, int totalLength)
    {
        String s = str;
        int size = str.length();
        for(int i = size; i < totalLength; i++)
        {
            s = "0" + s;
        }
        return s;
    }
}
